package com.bugjpa.service.impl;

import com.bugjpa.dao.BugDao;
import com.bugjpa.domain.Bug;
import com.bugjpa.service.IBugService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * @author mayuanbao
 * @date 2019-01-13 21:56
 */
@Service(value = "bugService")
@Transactional
public class BugServiceImpl implements IBugService {
    @Resource(name = "bugDao")
    private BugDao bugDao;

    @Override
    public Page<Bug> findAll(int page, int limit) {
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        Pageable pageable = PageRequest.of(page, limit, sort);
        return bugDao.findAll(pageable);
    }

    @Override
    public Long count() {
        return bugDao.count();
    }

    @Override
    public List<Object[]> findGroupByLevel() {
        return bugDao.findGroupByLevel();
    }
    @Override
    public List<Map<String, String>> findGroupByLevels() {
        return bugDao.findGroupByLevels();
    }
}
